var MaterialSearchForm = function () {
  var template = /* html */ `
    <sys-common-search request-url="materialSelectFilter/getMaterialSelectData" :request-data="{type:11}" :search="search"
      :search-field="searchField" label-width="100px" input-width="180px" v-loading.fullscreen.lock="loading">
      <template slot="prepend">
        <el-form-item label="预计结算日期">
          <el-date-picker v-model="search.startDate" class="form-input" value-format="timestamp" :editable="false"
            :picker-options="startDateOption" style="width:156px;"></el-date-picker>
          -
          <el-date-picker v-model="search.endDate" class="form-input" value-format="timestamp" :editable="false"
            :picker-options="endDateOption" style="width:156px;"></el-date-picker>
        </el-form-item>
        <el-form-item label="入库日期">
          <el-date-picker v-model="search.inStartDay" class="form-input" value-format="timestamp" :editable="false"
            :picker-options="inStartDayOption" style="width:156px;"></el-date-picker>
          -
          <el-date-picker v-model="search.inEndDay" class="form-input" value-format="timestamp" :editable="false"
            :picker-options="inEndDayOption" style="width:157px;"></el-date-picker>
        </el-form-item>
      </template>
      <template slot="append">
        <el-form-item label="入库类型">
          <el-select clearable v-model="search.type" class="form-input" style="width:180px;">
            <el-option v-for="type in typeList" :key="'type_'+type.value" :value="type.value" :label="type.label"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="是否结算">
          <el-select clearable v-model="search.isBalance" class="form-input" style="width:180px;">
            <el-option v-for="balance in balanceList" :key="'balance_'+balance.value" :value="balance.value" :label="balance.label">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="制单人" v-if="!search.fixedCreateUser">
          <el-select clearable v-model="search.createUser" class="form-input" style="width:180px;">
            <el-option v-for="user in userList" :key="'user_'+user.userId" :value="user.userId" :label="user.userName"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="单价">
          <el-input-number is-decimal-zero v-model="search.startPrice" placeholder="单价最小值" :controls="false" :min="0" :max="search.endPrice"
            :precision="2" style="width:110px"></el-input-number>
          <span>-</span>
          <el-input-number is-decimal-zero v-model="search.endPrice" placeholder="单价最大值" :controls="false" :precision="2"
            :min="search.startPrice?search.startPrice:0" style="width:110px"></el-input-number>
        </el-form-item>
      </template>
    </sys-common-search>
  `;

  return {
    mixins: [
      datePickerOptionsMixin('startDate', 'endDate'),
      datePickerOptionsMixin('inStartDay', 'inEndDay', 'inStartDayOption', 'inEndDayOption')
    ],

    props: {
      search: {
        type: Object,
        required: true
      },
      dropdownOption: {
        type: Object,
        default: function () {
          return {};
        }
      }
    },

    data: function () {
      return {
        loading: false,
        typeList: i18n.getDropDown('financeMgr.type', ['1', '2', '3']),
        balanceList: i18n.getDropDown('financeMgr.balance', ['0', '1']),
        userList: [],
        searchField: ['orderId', 'companyOrderId', 'customerNo', 'factoryNo', 'materialName', 'model', 'color',
          'providerName', 'materialDept'
        ]
      };
    },

    created: function () {
      var self = this;
      this.loading = true;
      this.setUserList().then(function () {
        self.loading = false;
      }).catch(function () {
        self.loading = false;
      });
    },

    methods: {
      setUserList: function () {
        var dropdownOption = this.dropdownOption;
        var userList = dropdownOption.userList;
        if (userList !== undefined) {
          this.userList = userList;
          return Promise.resolve(userList);
        }

        var self = this;
        return ajaxRequest('warehouseInSumMoney/getWarehouseUserList').then(function (userList) {
          dropdownOption.userList = userList;
          self.userList = userList;
          return userList;
        });
      }
    },

    components: {
      SysCommonSearch: SysCommonSearch
    },

    template: template
  };
}();
